"""
多层感知机简洁实现
"""

import tensorflow as tf
from d2l import tensorflow as d2l

if __name__ =='__main__':
    #net是网络模型，下面是两个层，隐藏加了激活函数，relu
    net = tf.keras.models.Sequential([
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Dense(10)])
    # 
    batch_size, lr, num_epochs = 256, 0.1, 10
    # 交叉熵损失函数
    loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
    # 迭代器
    trainer = tf.keras.optimizers.SGD(learning_rate=lr)

    # 测试集和训练集
    train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size)
    d2l.train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer)
    d2l.plt.show()
    




